#pragma once

#include <map>
#include <list>
#include "IDocListener.h"
class TreeItemData
{
public:
	enum TREE_ITEM_TYPE
	{
		ENTITY_ROOT,
		PLANE_ROOT,
		LAYER,
		ENTITY,
		PLANE
	};
	TreeItemData(TREE_ITEM_TYPE nType)
	{
		nItemType = nType;
		pFirstChild = NULL;
	}
	TREE_ITEM_TYPE nItemType;
	UINT nID;
	TreeItemData* pFirstChild;
};
//////////////////////////////////////////////////////////////////////////
class CGeomDocTree;
class TreeGroup
{
public:
	HTREEITEM hEntityRoot;
	HTREEITEM hCurLayer;
	HTREEITEM hSketchPlane;
public:
	void AddItemData(const ItemTrait& itemTrait)
	{
		m_EntityData.push_back(itemTrait);
	}
	void Restore(CGeomDocTree* pDocTree);
private:
	typedef std::list<ItemTrait> ItemTraitList;
	ItemTraitList m_EntityData;
};

//////////////////////////////////////////////////////////////////////////

class CGeomDocTree : public IDocListener
{
public:
	CGeomDocTree(void);
	~CGeomDocTree(void);

	virtual void OnNewDocument(CAnyDocument* pADoc);
	virtual void OnCloseDocument(CAnyDocument* pADoc);	
	virtual void OnAddShape(CAnyDocument* pADoc, const ItemTrait& itemTrait);
	virtual void OnActiveDocument(CAnyDocument* pADoc, bool bActive);
	// tree
	void SetTreeCtrl(CTreeCtrl* pTreeCtrl);

	bool ApplyIconsToTree(void);

	static bool InitTreeIcons(CImageList* pImageList);
	static void AddTreeItemIcon(UINT nID, HICON hIcon);
	void AddEntity(TreeGroup* pTreeGroup, const ItemTrait& itemTrait);
	void OnSelectChanged();
private:
	void InitTreeItems(TreeGroup* pTreeGroup);
	void ActivePlane(UINT nID);
	void ActiveEntity(UINT nID);

private:
	//HTREEITEM m_hEntityRoot;
	//HTREEITEM m_hCurLayer;
	//HTREEITEM m_hSketchPlane;

	CTreeCtrl* m_pTreeCtrl;
	static CImageList m_ImageList;

	typedef std::map<UINT, int> IconIndexMap;
	static IconIndexMap m_mapIconIdx;

	typedef std::map<CAnyDocument*, TreeGroup*> DocTreeMap;
	DocTreeMap m_mapDocTree;

	CAnyDocument* m_pCurADoc;
};
